if SERVER then
	registerCommand("spectate", "Causes you to spectate the player you specify", function(param)
		local specOn = "caller is spectating target"
		local specOff = "caller stopped spectating target"
		if param["settings"]["spec_msg_on"] then
			specOn = param["settings"]["spec_msg_on"]
		end
		if param["settings"]["spec_msg_off"] then
			specOff = param["settings"]["spec_msg_off"]
		end
		local specTable = {}
		specTable["caller"] = getCaller(param[1])
		local targ = string.Explode(" ", param[3])[1]
		local plyTarg = getPlayerByName(targ)
		if param[1]:IsValid() && plyTarg then
			specTable["target"] = plyTarg:GetName()
			if (not param[1]["moocow_spec"]) || param[1]["moocow_spec"] == -1 then
				param[1]["moocow_spec"] = 1
				param[1]:Spectate(OBS_MODE_CHASE)
				param[1]:SpectateEntity(plyTarg)
				param[1]["moocow_specpos"] = param[1]:GetPos()
				local callerWeaps = {}
				for i, weap in pairs (param[1]:GetWeapons()) do
					callerWeaps[i] = weap:GetClass()
				end
				param[1]["moocow_specweaps"] = callerWeaps
				param[1]["moocow_specactweap"] = param[1]:GetActiveWeapon():GetClass()
				param[1]:StripWeapons()
				display(param[1], "spectate", { plyTarg } , parseDisplayMessage(specOn, specTable))
			else
				param[1]["moocow_spec"] = -1
				param[1]:UnSpectate()
				param[1]:Spawn()
				param[1]:SetPos(param[1]["moocow_specpos"])
				for i, weap in pairs(param[1]["moocow_specweaps"]) do
					param[1]:Give(weap)
				end
				param[1]:SelectWeapon(param[1]["moocow_specactweap"])
				display(param[1], "spectate", { plyTarg } , parseDisplayMessage(specOff, specTable))
			end
		elseif param[1]["moocow_spec"] == 1 then
			param[1]["moocow_spec"] = -1
			param[1]:UnSpectate()
			param[1]:Spawn()
			param[1]:SetPos(param[1]["moocow_specpos"])
			for i, weap in pairs(param[1]["moocow_specweaps"]) do
					param[1]:Give(weap)
			end
			param[1]:SelectWeapon(param[1]["moocow_specactweap"])
			display(param[1], "spectate", { nil } , parseDisplayMessage(specOff, specTable))
		end
	end)
end